package com.epro.dx.adapter;

import java.util.List;


import android.content.ActivityNotFoundException;
import com.epro.dx.R;
import com.epro.dx.activity.LargeImageBrowseActivity;
import com.epro.dx.activity.SpecialActivity;
import com.epro.dx.indicator.IconPagerAdapter;
import com.epro.dx.util.ImageLoaderUtils;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.weipu.common.facade.model.BannerModel;
import android.content.Context;
import android.content.Intent;
import android.support.v4.view.PagerAdapter;
import android.text.TextUtils;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import com.weipu.common.util.Logger;

public class DetailProductImageAdapter extends PagerAdapter{
	private final static String TAG = "DetailProductImageAdapter";
	private Context mContext;

	private String[] imageUrls;

	private DisplayImageOptions options;
	
	private int screenWidth;

	public DetailProductImageAdapter(Context mContext, String[] imageUrls,int screenWidth) {
		this.mContext = mContext;
		this.imageUrls = imageUrls;
		this.screenWidth=screenWidth;
		options = ImageLoaderUtils.getImageLoaderOptions(
				R.drawable.default488_488, R.drawable.default488_488);
	}
	
	@Override
	public int getCount() {
		if (imageUrls != null)
			return imageUrls.length;
		return 0;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView((View) object);
	}

	@Override
	public Object instantiateItem(ViewGroup container, final int position) {
		ImageView imageView = new ImageView(mContext);
		imageView.setScaleType(ScaleType.FIT_XY);
		String filePath = imageUrls[position];
		if (!TextUtils.isEmpty(filePath) && null != imageView) {
			imageView.setTag(filePath);
			// imageWorker.loadImage(filePath, imageView);
			ImageLoader.getInstance()
					.displayImage(filePath, imageView, options);
		} else {
			imageView.setImageResource(R.drawable.default488_488);

		}
		imageView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent=new Intent();
				intent.setClass(mContext, LargeImageBrowseActivity.class);
				intent.putExtra("PhotoUrls", imageUrls);
				intent.putExtra("SelectedIndex", position);
				intent.putExtra("ScreenWidth", screenWidth);
				mContext.startActivity(intent);
			}
		});

		container.addView(imageView);
		return imageView;
	}

	@Override
	public boolean isViewFromObject(View view, Object object) {
		return view == object;
	}

	@Override
	public int getItemPosition(Object object) {
		// return super.getItemPosition(object);
		return POSITION_NONE;
	}

}
